//
//  ViewController.m
//  大头针的简单使用
//
//  Created by zpy on 15/12/6.
//  Copyright © 2015年 zpy. All rights reserved.
//

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "MyAnnotation.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 自定义大头针类
    MyAnnotation *annotation = [MyAnnotation new];
    annotation.coordinate = CLLocationCoordinate2DMake(23.08, 113.14);
    annotation.title = @"beijing";
    annotation.subtitle = @"welcome to beijing";
    [self.mapView addAnnotation:annotation];
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 获取点击的点
    CGPoint point = [[touches anyObject] locationInView:self.mapView];
    // 把点抓换成经纬度
    CLLocationCoordinate2D coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
    // 创建大头针
    MyAnnotation *annotation = [MyAnnotation new];
    annotation.coordinate = coordinate;
    
    annotation.title = @"源哥的窝";
    annotation.subtitle = @"神盾局x号基地";
    [self.mapView addAnnotation:annotation];
}


@end
